﻿@using MyWebProject.Models.QueryResult;
@using MyWebProject.Models.Entity;
@{
    List<MsgBoardResult> list = Model as List<MsgBoardResult>;
    if (list.Count == 0)
    {
        <span style="color:#808080;float:right">没有更多留言啦</span>
    }
    foreach (MsgBoardResult comment in list)
    {
        <div class="row" id="@comment.POST_ID.ToString()@comment.COMMENTS_ID.ToString()" style="margin-top:2px">
            <div class="col-md-3" style="float:left;padding-left:0px">
                <div class="row">
                    <img class="img-circle" style="float:left" src="@comment.AVATAR_URL">
                </div>
                <div class="row" style="font-size:x-small;word-break:break-all;text-align:center;">@comment.NICK_NAME</div>
            </div>

            <div class="col-md-9" style="float:left;padding-left:0px">
                <div class="alert alert-info" style="margin-bottom:0px;padding-bottom:20px">
                    <div class="row">
                        <p style="font-size:small;word-break:break-all; word-wrap:break-word ">
                            @Html.Raw(System.Web.HttpUtility.UrlDecode(comment.TEXT))
                        </p>
                    </div>
                    <div class="row" style="float:right;margin-right:5px">
                        <span style="font-size:xx-small;font-style:italic">@comment.DATE</span>
                        <a href="javascript:void(0)">
                            <em style="font-size:x-small" onclick="reply(@comment.POST_ID, @comment.COMMENTS_ID,'Blog/MsgBoardContent')">回复</em>
                        </a>
                    </div>
                </div>
            </div>
        </div>



        if (comment.REPLY != null)
        {
            foreach (COMMENTS m in comment.REPLY)
            {
                <div class="row" style="margin-top:2px;margin-left:20px">
                    <div class="col-md-3" style="float:left;padding-left:0px">
                        <div class="row">
                            <img class="img-circle" style="float:left" src="@m.AVATAR_URL">
                        </div>
                        <div class="row" style="font-size:x-small;word-break:break-all;text-align:center;">@m.NICK_NAME</div>
                    </div>
                    <div class="col-md-9" style="float:left;padding-left:0px">
                        <div class="alert alert-success" style="margin-bottom:0px;padding-bottom:20px">
                            <div class="row">
                                <p style="font-size:small;word-break:break-all; word-wrap:break-word ">
                                    @Html.Raw(System.Web.HttpUtility.UrlDecode(m.TEXT))
                                </p>
                            </div>
                            <div class="row" style="float:right;margin-right:5px">
                                @{  double day = DateTime.Now.Subtract(m.DATE).TotalDays;
                                    if (day > 1.0)
                                    {
                                        <span style="font-size:xx-small;font-style:italic;">@day.ToString().Split('.')[0] 天前</span>
}
                                    else
                                    {
                                        double hours = Math.Round(DateTime.Now.Subtract(m.DATE).TotalHours, 0);
                                        if (hours > 1)
                                        {
                                            <span style="font-size:xx-small;font-style:italic;">@hours 小时前</span>
}
                                        else
                                        {
                                            double minutes = Math.Round(DateTime.Now.Subtract(m.DATE).TotalMinutes, 0);
                                            <span style="font-size:xx-small;font-style:italic;">@minutes 分钟前</span>
}
                                    }
                                }
                            </div>
                        </div>
                    </div>
                </div>

                                            }
                                        }
                                    }
}
<script>
    //    function reply(postId, beforCommentsId) {
    //        var id = postId + '' + beforCommentsId;
    //        var lastId = $("#lastReplyId").val();
    //        $('#' + lastId + '_r').remove();
    //        $('#' + id).append('<div class="row" id=' + id + '_r>' +
    //    '<form role="form" id="boardForm_r" style="margin-bottom:10px">' +
    //    '    <input id="avatarUrl_r" style="display:none" />' +
    //        '<div class="form-group">' +
    //        '    <input type="text" class="form-control" id="nickName_r" placeholder="你的昵称">' +
    //       ' </div>' +
    //       ' <div class="form-group">' +
    //        '    <textarea class="form-control" id="comment_r" placeholder="我有话说"></textarea>' +
    //       ' </div>' +
    //     '   <button type="button" class="btn btn-info" onclick="leaveReply(' + postId + ',' + beforCommentsId + ')">说完了</button>' +
    //   ' </form>' +
    //'</div>');
    //        $("#avatarUrl_r").val(getAvatar());
    //        $("#nickName_r").val(getUserName());
    //        $("#nickName_r").attr("placeholder", getUserName());

    //        $("#lastReplyId").val(id);
    //        $("#boardForm_r").blur(function () {
    //            $('#' + id + '_r').remove();
    //        });
    //        $("#email_r").focus(function () {
    //            tips('boardForm_r', "支持gravatar头像功能,通用的email与头像关联方案,可以访问<a>http://cn.gravatar.com</a> 设置头像", 'info');
    //        });
    //    }

    //    function leaveReply(postId, beforCommentsId) {
    //        if ($('#nickName_r').val().length > 30) {
    //            tips('boardForm_r', "昵称过长", 'info');
    //            setTimeout("$('#tips').remove()", 5000);
    //            return;
    //        }
    //        if ($('#nickName_r').val().length == 0) {
    //            tips('boardForm_r', "不想给自己来个炫酷的昵称么", 'info');
    //            setTimeout("$('#tips').remove()", 5000);
    //            return;
    //        }
    //        if ($('#comment_r').val().length == 0) {
    //            tips('boardForm_r', "不想说点什么么", 'info');
    //            setTimeout("$('#tips').remove()", 5000);
    //            return;
    //        }
    //        $('#tips').remove();

    //        $.post('Blog/leaveComment', {
    //            "avatarUrl": $('#avatarUrl_r').val(),
    //            'nickName': $('#nickName_r').val(),
    //            'comment': $('#comment_r').val(),
    //            'beforCommentsId': beforCommentsId,
    //            'postId': postId,
    //        }, function (data) {
    //            getBoard('', '', postId);
    //            tips('boardForm_r', "感谢你的留言", 'success');
    //            setTimeout("$('#tips').remove()", 5000);
    //        });

    //    }
</script>
